import request from '@/api/axios'
import {AxiosPromise} from 'axios'
import {DataRes} from '@/api/config'

// 体检项目
export interface PhysicalItem{
  id:string
  itemCode:string
  itemName:string
}
// 仪器
export interface Instrument{
  id:string,
  instrumentName:string,
  instrumentCode:string,
  itemVOS:Array<PhysicalItem>
}

// 获取仪器及包含的体检项目列表
export const getInstrumentListReq = ():AxiosPromise<DataRes<Array<Instrument>>> => {
  return request({
    url:'/api/instrument/selectInstrumentAndItem',
    method:'get'
  })
}

// 登记信息
export interface SignedItem{
  instrumentId:string, //仪器id
  barcode:string, //条码号
  sampleNo:string, //标本号
  inspectTime:string, //检验时间
  sendTime:string, //送检时间
  sendDoctorName:string, //送检医生姓名
  sendDoctorId:string,
  checkupNo:string, //体检号
  personName:string, //姓名
  gender:string, //性别
  age:number //年龄
}

interface SearchParams{
  instrumentId:string,
  startInspectTime:string,
  endInspectTime:string
}

// 已登记人员列表
export const getSignedListReq = (params:SearchParams):AxiosPromise<DataRes<Array<SignedItem>>> => {
  return request({
    url:'/api/instrumentItem/selectList',
    method:'get',
    params
  })
}

//获取最大条码号
export const getSelectMaxSampleNoReq = (params:SearchParams):AxiosPromise<DataRes<number>> => {
  return request({
    url:'/api/instrumentItem/selectMaxSampleNo',
    method:'get',
    params
  })
}

// 登记表单
export type FromData = Partial<SignedItem>

//登记
export const saveInstrumentItemReq = (data:FromData):AxiosPromise<DataRes<DataRes<undefined>>> => {
  return request({
    url:'/api/instrumentItem/saveInstrumentItem',
    method:'post',
    data
  })
}

//条码信息
export interface PersonInfo{
  checkupNo:string,
  personName:string,
  gender:string,
  age:number,
  registerItemVOS:Array<PhysicalItem>
}
export interface GetInfoByBarcodeReqParams{
  barcode:string,
  instrumentId?:string
}

//根据条码获取详细信息
export const getInfoByBarcodeReq = (params:GetInfoByBarcodeReqParams):AxiosPromise<DataRes<PersonInfo>> => {
  return request({
    url:'/api/instrumentItem/selectByBarcode',
    method:'get',
    params
  })
}

//删除登记信息
export const deleteInstrumentItemReq = (data:Array<string>):AxiosPromise<DataRes<undefined>> => {
  return request({
    url:'/api/instrumentItem/deleteInstrumentItem',
    method:'post',
    data
  })
}




